package com.stockz.scanner.screen;

import java.util.List;

import com.stockz.core.model.Bar;
import com.stockz.core.util.ListUtil;
import com.stockz.core.util.BarUtil.BarValueType;
import com.stockz.scanner.screen.configuration.SimpleConsolidationScreenConfiguration;
import com.stockz.ui.swing.charting.util.MathUtil;

public class SimpleConsolidationScreen implements Screen<SimpleConsolidationScreenConfiguration> {

	private SimpleConsolidationScreenConfiguration configuration = 
			new SimpleConsolidationScreenConfiguration();
	
	@Override
	public SimpleConsolidationScreenConfiguration getConfiguration() {
		return configuration;
	}
	
	@Override
	public int getMandatorySpan() {
		return configuration.getSpan();
	}
	
	@Override
	public boolean isMatch(List<Bar> barList) {
		if(barList == null || barList.size() < configuration.getSpan())
			return false;
		
		double[] closes = ListUtil.convert(barList, BarValueType.CLOSE, configuration.getSpan());
		double max = MathUtil.max(closes);
		double min = MathUtil.min(closes);
		if(min == 0){
			min = 1;
		}
		return ((max-min)*100/min) < configuration.getRangePercentage();
	}

	public void setConfiguration(
			SimpleConsolidationScreenConfiguration configuration) {
		this.configuration = configuration;
	}
	
	
	
}
